package com.code_g.web.servlet;

import com.code_g.domain.PageBean;
import com.code_g.domain.User;
import com.code_g.service.Impl.UserServiceImpl;
import com.code_g.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/findUserByPageServlet")
public class FindUserByPageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String currentPage = request.getParameter("currentPage");
        String rows = request.getParameter("rows");
        if(currentPage == null){
            currentPage = "1";
        }
        if (rows == null){
            rows = "5";
        }
        Map<String, String[]> map = request.getParameterMap();
        UserService userService = new UserServiceImpl();
        PageBean<User> pageBean = userService.findUserBypage(currentPage, rows, map);
        request.setAttribute("pageBean",pageBean);
        request.setAttribute("map",map);
        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
